package com.kfirszt.elearning.elearningImport;

import java.io.File;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;

@XmlRootElement(name = "teryt")
@XmlAccessorType(XmlAccessType.FIELD)
public class TerytImport {
	
	private Catalog catalog;
	
	public Catalog getCatalog() {
		return catalog;
	}

	public void setCatalog(Catalog catalog) {
		this.catalog = catalog;
	}

	@XmlRootElement(name = "catalog")
	public static class Catalog{
		private List<Row> row;

		public List<Row> getRow() {
			return row;
		}

		public void setRow(List<Row> row) {
			this.row = row;
		}
	}
	
	@XmlRootElement(name = "row")
	@XmlAccessorType(XmlAccessType.FIELD)
	public static class Row{
		private List<Column> col;

		public List<Column> getCol() {
			return col;
		}

		public void setCol(List<Column> col) {
			this.col = col;
		}
	}
	
	@XmlRootElement(name = "col")
	@XmlAccessorType(XmlAccessType.FIELD)
	public static class Column{
		@XmlAttribute(name = "name")
		private String name;
		
		@XmlValue
		private String value;

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getValue() {
			return value;
		}

		public void setValue(String value) {
			this.value = value;
		}
	}
	
	public static TerytImport process() throws JAXBException {
		JAXBContext context = JAXBContext.newInstance(TerytImport.class);
		Unmarshaller unmarshaller = context.createUnmarshaller();
		return (TerytImport) unmarshaller.unmarshal(new File("/home/kamil/Pobrane/SIMC.xml"));
	}

}
